<template>
  <el-select
    :placeholder="$t('validate.pleaseInput')"
    v-model="value"
    clearable
    filterable
    style="width: 100%"
    size="small"
  >
    <el-option
      v-for="{ username, cname, userId } of options"
      :key="`${userId}-${username}`"
      :label="`${username}(${cname || '-'})`"
      :value="`${userId}-${username}`"
    />
  </el-select>
</template>

<script>
import { useRequest } from "vue-request";
import {getCmsUsers, getUsers} from "@/views/process/api/user";
import { get } from "lodash";
import { ref, watch } from "vue";

const formatResult = (data) => {
  console.log(data.data,'formatResult');
  return data.data.data
};

export default {
  emits: ["update:modelValue"],
  setup(props, { emit }) {
    const { data, loading }= useRequest(getCmsUsers, {
      formatResult,
    });
    // let data = ''
    // let loading = ''
    // getCmsUsers().then(res=>{
    //   data = res.data.data
    //   loading = res.data.loading
    //   console.log(res,data,loading,'getCmsUsers');
    // })
    const value = ref(null);
    watch(value, () => {
      emit("update:modelValue", value);
    });
    return {
      options: data,
      loading,
      value,
    };
  },
};
</script>

<style>
</style>
